package com.bdqn.ch11.interceptor;

import com.bdqn.ch11.interceptor.AuthorizationInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    private String[] excludePathPatterns;


    private AuthorizationInterceptor authorizationInterceptor;
    @Bean
    AuthorizationInterceptor authorizationInterceptor() {
        return new AuthorizationInterceptor();
    }


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        String[] pathPatterns = {"/**"}; //拦截路径规则
        //排除路径规则
        String[] excludePathPatterns = {"/", "/remember", "/index", "/index.html", "/login", "/dologin", "/css/**", "/fonts/**", "/images/**", "/js/**", "/localcss/**", "/localjs/**"};
        registry.addInterceptor(authorizationInterceptor()) //注册拦截
                .addPathPatterns(pathPatterns) //添加路径规则
                .excludePathPatterns(excludePathPatterns); //添加排除路径规
    }
}
